﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<CognisessDA.User>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <form id="personalisationForm" action="/Account/Personalisation" method="post" name="form1">
    <div class="why">
        <div class="why_l">
            <ul class="why_l_a">
                <li><strong>Your Account</strong></li>
                <li><a href="/Account/AccountSettings">Account Settings</a></li>
                <li>Personalisation</li>
                <li><a href="/Account/EmailPreferences">Email Preferences</a></li>
                <li><a href="/Account/TrainingReminders">Training Reminders</a></li>
                <li><a href="/Account/ChangePassword">Change Password</a></li>
                <li></li>
            </ul>
        </div>
        <div class="latest_r">
            <b class="application_t"><b class="application_tl"></b><b class="application_tr"></b>
            </b><b class="password_c">
                <h1 class="password_h1">
                    Personalisation</h1>
                <ul class="personali">
                    <li>
                        <label>
                            First Name:</label><span><input name="firstName" type="text" class="personali_input"
                                id="firstName" value="<%=(Session["user"] as CognisessDA.User).Firstname %>" /></span></li>
                    <li>
                        <label>
                            Last Name:</label><span><input name="lastName" type="text" class="personali_input"
                                id="lastName" value="<%=(Session["user"] as CognisessDA.User).Lastname %>" /></span></li>
                    <li>
                        <label>
                            Birthdate:</label>
                        <%
                            if ((Session["user"] as CognisessDA.User).BirthDate != null)
                            {
                                DateTime date = DateTime.Parse((Session["user"] as CognisessDA.User).BirthDate.ToString()); %>
                        <select id="sltDay" name="sltDay" >
                            <option selected="selected" value="<%=date.Day %>">
                                <%=date.Day%>
                            </opion>
                        </select>
                        <select id="sltMonth" name="sltMonth" onchange="CheckMonth(this.value)">
                            <%if (date.Month == 1)
                              {%>
                            <option selected="selected" value="1">January</option>
                            <% }%>
                            <%if (date.Month == 2)
                              {%>
                            <option selected="selected" value="2">February</option>
                            <% }%>
                            <%if (date.Month == 3)
                              {%>
                            <option selected="selected" value="3">March</option>
                            <% }%>
                            <%if (date.Month == 4)
                              {%>
                            <option selected="selected" value="4">April</option>
                            <% }%>
                            <%if (date.Month == 5)
                              {%>
                            <option selected="selected" value="5">May</option>
                            <% }%>
                            <%if (date.Month == 6)
                              {%>
                            <option selected="selected" value="6">June</option>
                            <% }%>
                            <%if (date.Month == 7)
                              {%>
                            <option selected="selected" value="7">July</option>
                            <% }%>
                            <%if (date.Month == 8)
                              {%>
                            <option selected="selected" value="8">August</option>
                            <% }%>
                            <%if (date.Month == 9)
                              {%>
                            <option selected="selected" value="9">September</option>
                            <% }%>
                            <%if (date.Month == 10)
                              {%>
                            <option selected="selected" value="10">October</option>
                            <% }%>
                            <%if (date.Month == 11)
                              {%>
                            <option selected="selected" value="11">November</option>
                            <% }%>
                            <%if (date.Month == 12)
                              {%>
                            <option selected="selected" value="12">December</option>
                            <% }%>
                        </select>
                        <select id="sltYear" name="sltYear" onchange="CheckYear(this.value)">
                            <option selected="selected" value="<%=date.Year %>">
                                <%=date.Year%></option>
                        </select>
                        <%}else {%>
                        <select id="sltDay" name="sltDay" >
                            <option selected="selected" value="">Select
                               
                            </opion>
                        </select>
                        <select id="sltMonth" name="sltMonth" onchange="CheckMonth(this.value)"><option selected="selected" value="">Select</option>                 
                        </select>
                        <select id="sltYear" name="sltYear" onchange="CheckYear(this.value)">     <option selected="selected" value="">Select</option>
                        </select>
                        <%} %>
                    </li>
                    <li>
                        <label>
                            Gender:</label><%--<%=Html.RadioButtonFor(m => m.Gender, (int)CognisessCommLib.EnumGender.Male)%>Male
            <%=Html.RadioButtonFor(m => m.Gender, (int)CognisessCommLib.EnumGender.Female)%>Female--%>
                        <%if ((Session["User"] as CognisessDA.User).Gender == 1)
                          {%>
                        <input type="radio" name="Gender" id="Gender1" value="1" checked />Male &nbsp;&nbsp;
                        <input type="radio" name="Gender" id="Gender2" value="0" />Female
                        <%} %>
                        <%else if ((Session["User"] as CognisessDA.User).Gender == 0)
                          {%>
                        <input type="radio" name="Gender" id="Radio3" value="1" />Male &nbsp;&nbsp;
                        <input type="radio" name="Gender" id="Radio4" value="0" checked />Female
                        <%}
                          else
                          { %>
                        <input type="radio" name="Gender" id="Radio5" value="1" checked />Male &nbsp;&nbsp;
                        <input type="radio" name="Gender" id="Radio6" value="0" />Female
                        <%} %>
                    </li>
                    <li class="personali_a">
                        <label>
                            Time Zone:</label>
                        <span>
                           <%= Html.DropDownListFor(model => model.TimeZone, (IEnumerable<SelectListItem>)ViewData["TimeZoneT"])%></span></li>
                    <li class="personali_a">
                        <label>
                            Education Level:</label>
                        <span>
                            <%= Html.DropDownListFor(model => model.EducationLevel, (IEnumerable<SelectListItem>)ViewData["Education"])%>
                                </span></li>
                </ul>
                <span class="personalis_button">
                    <input type="submit" name="button" id="button" value="" /></span> </b><b class="review_lf_d">
                        <b class="review_lf_dl"></b><b class="review_lf_dr"></b></b>
        </div>
    </div>
    </form>
    <style type="text/css">
        .error
        {
            text-align: left;
            color: Red;
        }
    </style>

    <script type="text/javascript" language="javascript">

        window.onload = function() {
            var aa = document.getElementById("sltYear");
            BindYear(aa.options[0].value);
            CheckYear(aa);
            //var objMonth = document.getElementById("sltMonth");
            // CheckMonth(objMonth);

        }
        function BindYear(aa) {
            var iYear = new Date().getFullYear();
            for (var i = iYear - 1; i > 1900; i--) {
                var mYear = document.getElementById("sltYear").value;
                if (i != aa) {
                    document.getElementById("sltYear").options.add(new Option("" + i + "", i));
                }
            }
        }
        //创建option元素，并追加到指定select元素  
        function append(o, v) {
            // var option=document.createElement("option");  
            //option.value=v;  
            // option.innerText=v;  
            // o.appendChild(option);  
            var option = new Option(v, v);
            o.options.add(option);
        }

        function CheckYear(obj) {
            var iYear = new Date().getFullYear();
            var iMonth = new Date().getMonth();
            var objMonth = document.getElementById("sltMonth");
            var objDay = document.getElementById("sltDay");
            var option_M = objMonth.options[0];
            objMonth.options.length = 0;
            objMonth.options.add(option_M);
            var option_D = objDay.options[0];
            objDay.options.length = 0;
            objDay.options.add(option_D);
            var mm = document.getElementById("sltMonth");
            if (obj != -1) {
                if (obj != iYear) {
                    for (var i = 1; i <= 12; i++) {
                        if (i != mm.options[0].value) {
                            if (i == 1)
                                document.getElementById("sltMonth").options.add(new Option("January", i));
                            if (i == 2)
                                document.getElementById("sltMonth").options.add(new Option("February", i));
                            if (i == 3)
                                document.getElementById("sltMonth").options.add(new Option("March", i));
                            if (i == 4)
                                document.getElementById("sltMonth").options.add(new Option("April", i));
                            if (i == 5)
                                document.getElementById("sltMonth").options.add(new Option("May", i));
                            if (i == 6)
                                document.getElementById("sltMonth").options.add(new Option("June", i));
                            if (i == 7)
                                document.getElementById("sltMonth").options.add(new Option("July", i));
                            if (i == 8)
                                document.getElementById("sltMonth").options.add(new Option("August", i));
                            if (i == 9)
                                document.getElementById("sltMonth").options.add(new Option("September", i));
                            if (i == 10)
                                document.getElementById("sltMonth").options.add(new Option("October", i));
                            if (i == 11)
                                document.getElementById("sltMonth").options.add(new Option("November", i));
                            if (i == 12)
                                document.getElementById("sltMonth").options.add(new Option("December", i));
                        }
                    }
                }
            }
        }

        function CheckMonth(obj) {
            var iYear = document.getElementById("sltYear").value;
            var iMonth = document.getElementById("sltMonth").value;
            var objDay = document.getElementById("sltDay");
            var option_f = objDay.options[0];
            objDay.options.length = 0;
            objDay.options.add(option_f);
            if (iMonth == 1 || iMonth == 3 || iMonth == 5 || iMonth == 7 || iMonth == 8 || iMonth == 10 || iMonth == 12) {
                for (var j = 1; j <= 31; j++) {
                    if (j != option_f.value) {
                        append(objDay, j);
                    }
                }
            }
            if (iMonth == 4 || iMonth == 6 || iMonth == 9 || iMonth == 11) {
                for (var j = 1; j <= 30; j++) {
                    if (j != option_f.value) {
                        append(objDay, j);
                    }
                }
            }
            if (iMonth == 2) {
                if (iYear % 4 == 0 && (iYear % 100 != 0 || iYear % 400 == 0)) {
                    for (var j = 1; j <= 29; j++) {
                        if (j != option_f.value) {
                            append(objDay, j);
                        }
                    }
                }
                else {
                    for (var j = 1; j <= 28; j++) {
                        if (j != option_f.value) {
                            append(objDay, j);
                        }
                    }
                }
            }
        }
        function CheckDay(obj) {
        }
        $().ready(function() {
            $("#personalisationForm").validate({
                rules: {
                    firstName: { required: true, rangelength: [1, 20] },
                    lastName: { required: true, rangelength: [1, 20] },
                    sltYear: { digits: true },
                    sltMonth: { digits: true },
                    sltDay: { digits: true },
                    Education: { required: true },
                    Timezone: { required: true }
                },
                messages: {
                    firstName: { required: "Please select your FirstName.", rangelength: "firstName cannot exceed 20 characters." },
                    lastName: { required: "Please select your LastName.", rangelength: "LastName cannot exceed 20 characters." },
                    sltYear: { digits: "Please select your Year." },
                    sltMonth: { digits: "Please select your Month." },
                    sltDay: { digits: "Please select your Day." },
                    Education: { required: "Please select your Education." },
                    Timezone: { required: "Please select  your Time Zone." }
                },
                remote: {
                    url: "Account/CognisessExperience",
                    type: "post",
                    dataType: "json",
                    data: {
                        username: function() {
                            return $("#firstName").val();
                            return $("#Education").val();
                            return $("#Gender").val();
                            return $("#Timezone").val();
                            return $("#sltYear").val();
                            return $("#sltMonth").val();
                            return $("#sltDay").val();
                            return $("#lastName").val();
                        }
                    }
                }
            });
        });
        $.validator.setDefaults({
            submitHandler: function(form) { form.submit(); }
        });

        function checkShow() {
            location.href = "/Home";
        }
    </script>

</asp:Content>
